package eu.horyzont.systemyrozproszone.systemmagazynowy.serwer;

import eu.horyzont.systemyrozproszone.systemmagazynowy.serwer.session.Session;
import eu.horyzont.systemyrozproszone.systemmagazynowy.serwer.entities.*;
import eu.horyzont.systemyrozproszone.systemmagazynowy.serwer.httplistener.HttpListener;
import java.io.IOException;
import java.util.List;
import org.apache.log4j.Logger;

/**
 * The program's entry point.
 * @author pawel
 */
public class Server {
    
    private static final Logger logger = Logger.getLogger(Server.class);
    
    public static void main(String[] args) throws IOException {
//        HttpListener http = Utils.getHttpListener();
//        http.start();
//        
        exampleUse();
    }
    
    // TODO: it's just example. Remove it ASAP
    private static void exampleUse() throws IOException {
        Session session = Utils.getSession();
        
        Employee employee = new Employee();
        employee.setFirstName("Jan");
        employee.setLastName("Kowalski");
        session.save(employee);
        
        employee = new Employee();
        employee.setFirstName("Anna");
        employee.setLastName("Nowak");
        session.save(employee);
        
        Employee janKowalski = session.findSingle("find employee where firstName=?", "Jan");
        logger.info("Jan Kowalski: " + janKowalski);
        
        List<Employee> employees = session.find("find employee");
        for (Employee emp : employees) {
            logger.info(String.format("%s %s: %s", emp.getFirstName(), emp.getLastName(), emp));
        }
    }
    
}
